using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 生产工单控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ProductionOrderController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public ProductionOrderController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取生产工单列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<ProductionOrderDto>>> GetProductionOrders([FromQuery] ProductionOrderQueryDto query)
        {
            return await _consoleService.GetProductionOrdersAsync(query);
        }

        /// <summary>
        /// 获取生产工单详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<ProductionOrderDto>> GetProductionOrder(int id)
        {
            return await _consoleService.GetProductionOrderAsync(id);
        }

        /// <summary>
        /// 创建生产工单
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<ProductionOrderDto>> CreateProductionOrder([FromBody] ProductionOrderDto dto)
        {
            return await _consoleService.CreateProductionOrderAsync(dto);
        }

        /// <summary>
        /// 更新生产工单
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<ProductionOrderDto>> UpdateProductionOrder([FromBody] ProductionOrderDto dto)
        {
            return await _consoleService.UpdateProductionOrderAsync(dto);
        }

        /// <summary>
        /// 删除生产工单
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteProductionOrder(int id)
        {
            return await _consoleService.DeleteProductionOrderAsync(id);
        }
    }
} 